(define a 2)
(define b 4)

(define (double x) (+ x x))
(define (halve x) (/ x 2))
(define (even? x) (= (remainder x 2) 0))

(display "ex1-18:\n")
(define (fast-mul-r a b)
    (cond ((= 0 b) 0)
        ((even? b) (fast-mul-r (double a) (halve b)))
        (else (+ a (fast-mul-r a (- b 1)) ))))
        
(display (fast-mul-r a b))
(newline)

(define (fast-mul-i a b)
    (define (fast-mul-i-iter a b m)
        (cond ((= b 0) m)
            ((even? b) (fast-mul-i-iter (double a) (halve b) m))
            (else (fast-mul-i-iter a (- b 1) (+ m a)))))
    (fast-mul-i-iter a b 0))
    
(display (fast-mul-i a b))